package com.polaris.live.dialog

import android.content.Context
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.databinding.DialogRoomDiyBackgroundDetailBinding
import com.polaris.live.resp.back_resp.UploadTimesConfig
import com.polaris.live.utils.image.loadImage

/**
 * 房间背景说明
 *
 * @author Created by 半仙 on 2024/12/23/023 14:38
 */
class RoomDiyBackgroundDetailDialog(
    context: Context,
    private val mUploadTimesConfig: UploadTimesConfig,
) : BottomPopupView(context) {

    override fun getImplLayoutId() = R.layout.dialog_room_diy_background_detail

    private lateinit var mBinding: DialogRoomDiyBackgroundDetailBinding

    override fun onCreate() {
        super.onCreate()
        mBinding = DialogRoomDiyBackgroundDetailBinding.bind(popupImplView)

        val bottomView = mBinding.vLine
        val lp = bottomView.layoutParams as ViewGroup.LayoutParams
        lp.height = NavigationBarUtils.getNavigationBarHeight(context)
        bottomView.layoutParams = lp

        mBinding.closeImg.setOnSingleClickListener {
            dismiss()
        }

        mBinding.tvCommonTimes.text = mUploadTimesConfig.normalUploadTimes.toString()
        mBinding.tvVipTimes.text = mUploadTimesConfig.vipUploadTimes.toString()

        Glide.with(context).loadImage("static/decoration/profile-background/explain_1.png").into(mBinding.ivImage1)
        Glide.with(context).loadImage("static/decoration/profile-background/explain_2.png").into(mBinding.ivImage2)
        Glide.with(context).loadImage("static/decoration/profile-background/explain_3.png").into(mBinding.ivImage3)
    }

    companion object {

        fun show(context: Context, uploadTimesConfig: UploadTimesConfig) {
            XPopup.Builder(context)
                .isDestroyOnDismiss(true)
                .asCustom(RoomDiyBackgroundDetailDialog(context, uploadTimesConfig))
                .show()
        }
    }
}